﻿using Inovout;
using Inovout.Data.Domain;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace KuaJing.Security.Domain
{
    public partial class Privilege : TreeDataObject<Privilege>
    {
        public Privilege()
        { 
        }
        public Privilege(Privilege parent)
        {
            this.Parent = parent;
        }

        public override ISet<Privilege> Children { get { return base.Children; } }
        public override Privilege Parent { get { return base.Parent; } set { base.Parent = value; } }
      

        public virtual Resource Resource { get; set; }

        public virtual HttpMethod Operation { get; set; }

        public override bool Equals(DataObject that)
        {
            Privilege privilege = that as Privilege;
            if (privilege.Resource.Name.ToLower().TrimEnd('/') == this.Resource.Name.ToLower().TrimEnd('/') && 
                privilege.Operation == this.Operation)
            {
                return true;
            }
            return false;
        }

        public override int GetHashCode()
        {
           // HashCodeCombiner hashCodeCombiner = new HashCodeCombiner();
           // hashCodeCombiner.Add(this.Resource);
           // hashCodeCombiner.Add(this.Operation);
            return this.Resource.Name.GetHashCode() ^ this.Operation.GetHashCode();
        }

    }
}
